<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script src="https://libs.baidu.com/jquery/1.6.4/jquery.min.js"></script>

<script type="text/javascript">
	$(document).ready(function(){
		var userStr = localStorage.getItem('user');
		if (userStr == null || userStr ==  "undefined" || userStr == "") {
			$("#show").html("暂无用户信息");
		}else {
			var user  = JSON.parse(userStr);
			var timestamp = new Date().getTime();
			if (timestamp - user.time > 5000) {
				$("#show").html("用户信息已过期");	
			}else{
				$("#show").html(userStr);	
			}
		}

		$("#btn").click(function(){
		  	$.get("/t/user", function(result){
		  		$("#show").html(userStr);
  			});

		});

	  	$("#btn1").click(function(){
	  		var userStr = localStorage.getItem('user');
			if (userStr == null || userStr ==  "undefined" || userStr == "") {
			  	$.get("/t/user", function(result){
			  		var userStr = JSON.stringify(result);
			  		localStorage.setItem('user',userStr);
			  		$("#show").html(userStr);
	  			});
			}else{
				var user  = JSON.parse(userStr);
				var timestamp = new Date().getTime();
				if (timestamp - user.time > 5000) {
					$.get("/t/user", function(result){
				  		var userStr = JSON.stringify(result);
				  		localStorage.setItem('user',userStr);
				  		$("#show").html(userStr);
		  			});
				}else{
					$("#show").html(userStr);	
				}
			}

		});

		$("#btn2").click(function(){
		  	$.get("/t/activityUserCount", function(result){
		  		$("#show2").html("参与人数: "+result);
  			});

		});

		$("#btn3").click(function(){
		  	$.get("/c/activityUserCount", function(result){
		  		$("#show2").html("参与人数: "+result);
  			});

		});


		$("#btn4").click(function(){
		  	$.get("/t/chance?type=1", function(result){
		  		$("#show3").html("概率控制: "+result);
  			});
		});

		$("#btn5").click(function(){
		  	$.get("/t/chance?type=2", function(result){
		  		$("#show3").html("概率控制: "+result);
  			});
		});

		$("#btn6").click(function(){
		  	$.get("/m/times", function(result){
		  		$("#show4").html("次数统计: "+result);
  			});
		});

	});
</script>
</head>

<body>
<p id="show">暂无用户信息</p>
<button id="btn">获取用户信息</button>
<button id="btn1">获取用户信息客户端缓存</button>

<p id="show2">参与人数:</p>
<button id="btn2">查询参与人数</button>
<button id="btn3">查询参与人数nginx缓存</button>

<p id="show3">概率控制:</p>
<button id="btn4">基本概率</button>
<button id="btn5">概率翻倍</button>

<p id="show4">次数统计:</p>
<button id="btn6">次数+1</button>


</body>
</html>